<{include file="public_html/header.html"}>
<{include file="public_html/left_menu.html"}>
	<!-- content starts -->
	<blockquote class="layui-elem-quote"><{$action}></blockquote>

	<fieldset class="layui-elem-field">
  		<legend>筛选</legend>
			<div class="layui-field-box">
				<form class="layui-form layui-form-pane1" method="post">
            	<div class="layui-form-item">
		            <div class="layui-inline">
			            <select name="subject_id" id="subject_id" lay-filter="subject">
                        	<option value="0">选择科目</option>
                            <{foreach from=$subject item=item}>
                                <option value="<{$item.id}>" <{if isset($conditions['subject_id']) AND $conditions['subject_id'] == $item.id}>selected<{/if}>><{$item.title}></option>
                            <{/foreach}>
                        </select>
				  	</div>

				  	<div class="layui-inline">
			            <select name="chapter_id" id="chapter_id" lay-filter="chapter_id">
							<option value="0">选择章节</option>
							<{if $chapter_list_data|count  > 0}>
								<{foreach from=$chapter_list_data item=item}>
									<{if $item.sub|count > 0}>
										<{foreach from=$item.sub item=item1}>
											<optgroup label="<{$item1.title}>">
											<{if $item1.sub|count > 0}>
												<{foreach from=$item1.sub item=item2}>
													<option <{if $item2.id == $topic_info.chapter_id}> selected <{/if}> value="<{$item2.id}>"><{$item2.title}></option>
												<{/foreach}>
											<{/if}>
											</optgroup>
										<{/foreach}>
									<{/if}>
								<{/foreach}>
							<{/if}>
						</select>
				  	</div>

				  	<div class="layui-inline">
			    		<select name="source_type">
                            <option value="0" <{if isset($conditions['source_type']) AND $conditions['source_type'] == 0}>selected<{/if}>>题目来源</option>
                            <option value="1" <{if isset($conditions['source_type']) AND $conditions['source_type'] == 1}>selected<{/if}>>系统</option>
                            <option value="2" <{if isset($conditions['source_type']) AND $conditions['source_type'] == 2}>selected<{/if}>>第三方学校</option>
                        </select>
			    	</div>

			    	<div class="layui-inline">
						<input class="layui-input" name="start_time" value="<{if $conditions['start_time']|default:0 != 0}><{$conditions['start_time']}><{/if}>" placeholder="开始日" id="LAY_demorange_s">
					</div>

					<div class="layui-inline">
						<input class="layui-input" name="end_time" value="<{if $conditions['end_time']|default:0 != 0}><{$conditions['end_time']}><{/if}>"  placeholder="截止日" id="LAY_demorange_e">
					</div>
		    	</div>

		    	<div class="layui-form-item">
		    		<div class="layui-inline">
			    		<select name="type">
                        	<option value="0" <{if isset($conditions['type']) AND $conditions['type'] == 0}>selected<{/if}>>题型</option>
                            <option value="1" <{if isset($conditions['type']) AND $conditions['type'] == 1}>selected<{/if}>>单选题</option>
                            <option value="2" <{if isset($conditions['type']) AND $conditions['type'] == 2}>selected<{/if}>>多选题</option>
                            <option value="3" <{if isset($conditions['type']) AND $conditions['type'] == 3}>selected<{/if}>>判断题</option>
                            <option value="4" <{if isset($conditions['type']) AND $conditions['type'] == 4}>selected<{/if}>>计算分析题</option>
                            <option value="7" <{if isset($conditions['type']) AND $conditions['type'] == 7}>selected<{/if}>>不定向选择题</option>
                            <option value="8" <{if isset($conditions['type']) AND $conditions['type'] == 8}>selected<{/if}>>名词解释</option>
                            <option value="9" <{if isset($conditions['type']) AND $conditions['type'] == 9}>selected<{/if}>>简答题</option>
                        </select>
			    	</div>

			    	<div class="layui-inline">
			            <select name="difficulty_level">
                        	<option value="0">题目难易度</option>
                            <option value="3" <{if $conditions.difficulty_level|default:0 == 3}>selected<{/if}>>难</option>
                            <option value="2" <{if $conditions.difficulty_level|default:0 == 2}>selected<{/if}>>中</option>
                            <option value="1" <{if $conditions.difficulty_level|default:0 == 1}>selected<{/if}>>易</option>
                        </select>
				  	</div>
			    	
			    	<div class="layui-inline">
			    		<input type="text" class="layui-input" style="width:200px;" placeholder="题干"  name="subject_text" value="<{if !empty($conditions['subject_text'])}><{$conditions['subject_text']}><{/if}>" />
			    	</div>

		    		<div class="layui-inline">
			    		<button type="submit" class="layui-btn">搜索</button>
			    		<a class="layui-btn" href="/topic/add"><i class="layui-icon"></i> 添加题目</a>
			    		<a class="layui-btn" href="/topic/import"><i class="layui-icon"></i> 导入题目</a>
			    	</div>
		    	</div>
            </form>
    	</div>
	</fieldset>

	<form class="layui-form layui-form-pane1" method="post" delete_action="/topic/delete">
		<table class="layui-table" lay-even lay-skin="row">
		  	<thead>
			  	<tr>
				  	<th>ID</th>
				  	<th width="40%">题目内容</th>
				  	<th>题目归属</th>
				  	<th>题目类型</th>
				  	<th>题目难度</th>
				  	<th>创建时间</th>
				  	<th>操作</th>
			  	</tr>
		  	</thead>   
		  	<tbody>
		  	<{foreach from=$topic_list item=item}>
			  	<tr>
			  		<td class="center">
						<input type="checkbox" name="ids[]" value="<{$item['id']}>" title="<{$item['id']}>">
			  		</td>
			  		<td class="center" title="<{$item['subject_text']|strip_tags}>"><a href="/topic/edit/<{$item['id']}>"><{$item['subject_text']|strip_tags|cut_str:50}></a></td>
			  		<td class="center"><{if $item['school_id'] == 0}>系统<{else}>第三方学校<{/if}></td>
			  		<td class="center"><{if $item['type'] == 1}>单选题<{elseif $item['type'] == 2}>多选题<{elseif $item['type'] == 3}>判断题<{elseif $item['type'] == 4}>计算分析题<{elseif $item['type'] == 5}>填空题<{elseif $item['type'] == 6}>计算题<{elseif $item['type'] == 7}>不定向选择题<{elseif $item['type'] == 8}>名词解释<{elseif $item['type'] == 9}>简答题<{/if}></td>
			  		<td class="center"><{if $item['difficulty_level'] == 1}>易<{elseif $item['difficulty_level'] == 2}>中<{elseif $item['difficulty_level'] == 3}>难<{/if}></td>
			  		<td class="center"><{$item['add_time']|date_format:'%Y-%m-%d %H:%M:%S'}></td>
			  		<td class="center">
						<a class="layui-btn layui-btn-primary layui-btn-small" href="/topic/edit/<{$item['id']}>" target="_blank"><i class="layui-icon"></i></a>
						<a class="layui-btn layui-btn-primary layui-btn-small delete_data" href="/topic/delete/<{$item['id']}>"><i class="layui-icon"></i></a>
					</td>
			  	</tr>
		  	<{/foreach}>
		  	<{if $topic_list|count eq 0}>
		  		<tr>
			  		<td class="center" style=" height:120px; text-align:center;line-height:120px;" colspan="8">
						赞无数据！
					</td>
			  	</tr>
		  	<{/if}>
		  	<tr>
				<td class="center" colspan="7">
					<input type="checkbox" lay-filter="checkbox_all" title="全选">
					<button id="delete" class="layui-btn layui-btn-primary layui-btn-small" style="margin-top:4px;"><i class="layui-icon"></i> 批量删除</button>
				</td>
			</tr>
	  		</tbody>
	  	</table>
  	</form>
  	<div class="layui-box layui-laypage layui-laypage-default">
		<{$pagination}>
	</div>      
<{include file="public_html/footer.html"}>
<script>
	layui.use(['form', 'jquery', 'layedit'], function(){
		var form = layui.form(),$ = layui.jquery;
		form.on('select(subject)', function(data){
			var ii = layer.load();
			var subject_id = $(data.elem).val();
			$("#chapter_id").html('<option value="0">请选择章节</option>');  
			form.render('select');
			$.ajax({
				type: "POST",
				url: "/topic/ignore_get_subject_chapter",
				dataType:"json",
				data:{subject_id:subject_id},
				success: function(result){
					layer.close(ii);
					if(result.code == 1){
						var html ='';
						$.each(result.chapter_list, function(i, obj) {
							if(obj.sub){
								html += '<optgroup label="'+ obj.title+'">';
                                $.each(obj.sub, function(j, obj1) {
                                    html += '<option value="'+obj1.id+'">'+obj1.title+'</option>';
                                });
                                html += '</optgroup>'
                            }
						});
						$("#chapter_id").append(html);
						form.render('select');
					}
				}
			});
		});

		<{if $conditions['subject_id']|default:0 > 0}>
		$.ajax({
			type: "POST",
			url: "/topic/ignore_get_subject_chapter",
			dataType:"json",
			data:{subject_id:"<{$conditions['subject_id']|default:0}>"},
			success: function(result){
				if(result.code == 1){
					var html ='';
					$.each(result.chapter_list, function(i, obj) {
						if(obj.sub){
							html += '<optgroup label="'+ obj.title+'">';
                            $.each(obj.sub, function(j, obj1) {
                            	if(obj1.id == "<{$conditions.chapter_id}>"){
                            		html += '<option value="'+obj1.id+'" selected>'+obj1.title+'</option>';
                            	}else{
                            		html += '<option value="'+obj1.id+'">'+obj1.title+'</option>';
                            	}
                                
                            });
                            html += '</optgroup>'
                        }
					});
					$("#chapter_id").append(html);
					form.render('select');
				}
			}
		});
		<{/if}>
	});

	layui.use('laydate', function(){
		var laydate = layui.laydate;
		var start = {
			min: '2016-11-31 23:59:59'
			,max: laydate.now(+1)
			,istoday: false
			,choose: function(datas){
				end.min = datas; //开始日选好后，重置结束日的最小日期
				end.start = datas //将结束日的初始值设定为开始日
			}
		};

		var end = {
			min: '2016-11-31 23:59:59'
			,max: laydate.now(+1)
			,istoday: false
			,choose: function(datas){
				start.max = datas; //结束日选好后，重置开始日的最大日期
			}
		};

		document.getElementById('LAY_demorange_s').onclick = function(){
			start.elem = this;
			laydate(start);
		}
		document.getElementById('LAY_demorange_e').onclick = function(){
			end.elem = this
			laydate(end);
		}
	});
</script>